/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */

import java.io.*;

/**
 * <p>Project: app2022 - Exam03
 * <p>Powered by webrx On 2022-01-19 16:55:05
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Exam03 {
    public static void main(String[] args) {
        String src = "src.txt";
        try (var r = new BufferedReader(new FileReader(src))) {
            int num = 0;
            while (r.ready()) {
                String line = String.format("%4d %s%n", ++num, r.readLine());
                append(line, new File("src2.txt"));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void append(String source, File dst) {
        try (var out = new BufferedWriter(new FileWriter(dst, true))) {
            out.write(source);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
